<?php
require_once '../sub/init.php';
header("Cache-control: private");
require_once 'chkUadm.php';
if(!in_array('urole',$QXARR))exit(noauth());
require_once ZEAI.'cache/config_up.php';
require_once ZEAI.'sub/zeai_up_func.php';
require_once ZEAI.'cache/config_vip.php';
$switch = json_decode($_ZEAI['switch'],true);
//检查性别库
$ifsex = true;
$row = $db->ROW(__TBL_UDATA__,"subjsonstr","fieldname='sex'","num");
if ($row){$sex_ARR = json_decode($row[0],true);if(!is_array($sex_ARR) || count($sex_ARR)==0)$ifsex = false;}else{$ifsex = false;}
if (!$ifsex)alert_adm('性别出错请联系开发者QQ797311','close');
//检查性别库 结束
if ($submitok == 'ajax_addupdate' || $submitok == 'ajax_modupdate'){
	$grade=intval($grade);$if2=intval($if2);$title=trim($title);
	if (empty($title) )json_exit(array('flag'=>0,'msg'=>'请输入用户组名称','focus'=>'title'));
	if (str_len($title) >20)json_exit(array('flag'=>0,'msg'=>'亲，用户组名称【'.$title.'】这么长有意义么？ 请不要超过20字节','focus'=>'title'));
	$title = dataIO($title,'in',50);
	if (!ifint($grade) )json_exit(array('flag'=>0,'msg'=>'请输入权重等级 1~20','focus'=>'grade'));
	if ($grade > 20)$grade = 20;
	if ($grade == 0)$grade = 1;
	$if2=intval($if2);
	if (!ifint($if2) && $grade>1)json_exit(array('flag'=>0,'msg'=>'请选择VIP有效期限天数','focus'=>'if2'));
	if ($if2 > 9999)$if2 = 9999;
	$sj_rmb1=abs(floatval($sj_rmb1));
	$sj_rmb2=abs(floatval($sj_rmb2));
	if ($sj_rmb1<=0 && $grade>1)json_exit(array('flag'=>0,'msg'=>'请输入服务价格【男】','focus'=>'sj_rmb'));
	if ($sj_rmb2<=0 && $grade>1)json_exit(array('flag'=>0,'msg'=>'请输入服务价格【女】','focus'=>'sj_rmb'));
	if ($switch_Smode!=1 && $switch_Smode!=2)json_exit(array('flag'=>0,'msg'=>'请选择用户服务模式【线上服务】还是【线下服务】','focus'=>'grade'));
}
switch ($submitok){
	case "ajax_addupdate":
		if ($db->ROW(__TBL_ROLE__,"id","kind=1 AND title='$title'"))json_exit(array('flag'=>0,'msg'=>'用户组名称【'.$title.'】出现重复，请重试','focus'=>'title'));
		$grade = abs(intval($grade));
		if ($grade>20 || $grade==0)json_exit(array('flag'=>0,'msg'=>'请重输入权重1~20','focus'=>'grade'));
		if ($db->ROW(__TBL_ROLE__,"id","kind=1 AND grade=".$grade))json_exit(array('flag'=>0,'msg'=>'权重【'.$grade.'】出现重复，请重输','focus'=>'grade'));
		//
		foreach ($sex_ARR as $k=>$v) {
			$file = $_FILES["pic".$k];
			if (empty($file['tmp_name']))json_exit(array('flag'=>0,'msg'=>'请给当前用户组【'.$v['v'].'】上传一个牛逼点的图标吧'));
			if (getpicextname($file['tmp_name']) != 'png' || !ifpic($file['tmp_name']))json_exit(array('flag'=>0,'msg'=>'当前用户组【'.$v['v'].'】必须是png透明格式图片'));
			@up_send($file,'p/img/grade'.$v['i'].$grade.'.png',0,$_UP['upMsize']);
		}
		//
		$db->query("INSERT INTO ".__TBL_ROLE__." (title,grade,if2,kind) VALUES ('$title',$grade,$if2,1)");
		$roleid=$db->insert_id();
		AddLog('新增用户组【'.$title.'，权重：'.$grade.'，时长：'.get_if2_title($if2).'】');
		json_exit(array('flag'=>1,'roleid'=>$id,'msg'=>'新增成功'));
	break;
	case "ajax_modupdate":
		if(!ifint($id))json_exit(array('flag'=>0,'msg'=>'forbidden'));
		$grade = abs(intval($grade));
		if ($grade != $oldgrade){
			if ($db->ROW(__TBL_ROLE__,"id","kind=1 AND grade=".$grade))json_exit(array('flag'=>0,'msg'=>'权重【'.$grade.'】出现重复，请重输','focus'=>'grade'));
		}
		//
		foreach ($sex_ARR as $k=>$v) {
			$file = $_FILES["pic".$k];
			if (!up_check_file_exists('p/img/grade'.$v['i'].$oldgrade.'.png') && empty($file['tmp_name']))json_exit(array('flag'=>0,'msg'=>'请给当前用户组【'.$v['v'].'】上传一个牛逼点的图标吧'));//老图不存在，新的为空
			if (!empty($file['tmp_name'])){
				if (getpicextname($file['tmp_name']) != 'png' || !ifpic($file['tmp_name']))json_exit(array('flag'=>0,'msg'=>'当前用户组【'.$v['v'].'】必须是png透明格式图片'));
				@up_send($file,'p/img/grade'.$v['i'].$grade.'.png',0,$_UP['upMsize']);
			}
		}
		if ($grade != $oldgrade){//等级有变化
			foreach ($sex_ARR as $v){@up_adm_rename_pic('p/img/grade'.$v['i'].$oldgrade.'.png','p/img/grade'.$v['i'].$grade.'.png');}
			$db->query("UPDATE ".__TBL_USER__." SET grade=".$grade." WHERE grade=".$oldgrade);
		}
		//
		$row2 = $db->ROW(__TBL_ROLE__,"title,grade,if2","id=".$id,'num');$oldtitle= $row2[0];$oldgrade= $row2[1];$oldif2= $row2[2];
		AddLog('修改用户组，原组：【'.$oldtitle.'，权重：'.$oldgrade.'，时长：'.get_if2_title($oldif2).'】->新组：【'.$title.'，权重：'.$grade.'，时长：'.get_if2_title($if2).'】');
		//
		$db->query("UPDATE ".__TBL_ROLE__." SET grade=".$grade.",title='$title',if2=".$if2." WHERE id=".$id);
		json_exit(array('flag'=>1,'roleid'=>$id));
	break;
	case "delpicupdate":
		if (!ifint($id))alert_adm_parent('forbidden','back');
		@up_send_admindel('p/img/grade'.$sg.'.png');
		//
		$row2 = $db->ROW(__TBL_ROLE__,"title,grade,if2","id=".$id,'num');$title= $row2[0];$grade= $row2[1];$if2= $row2[2];
		AddLog('删除用户组【'.$title.'，权重：'.$grade.'，时长：'.get_if2_title($if2).'】图标');
		//
		header("Location: ".SELF."?submitok=mod&id=".$id);
	break;
	case "ajax_delupdate":
		if(!ifint($id))json_exit(array('flag'=>0,'msg'=>'forbidden'));
		//不能删光，必须要留一个
		$rolenum = $db->COUNT(__TBL_ROLE__,"kind=1");
		if ($rolenum <= 1){
			$db->query("UPDATE ".__TBL_ROLE__." SET ifdefault=1");
			json_exit(array('flag'=>0,'msg'=>'亲，不能删光啊，至少要留一个啊'));	
		}
		//删除图标，获取是否默认用户组标记
		$row = $db->ROW(__TBL_ROLE__,"grade,ifdefault,title,if2","id=".$id,'num');
		if ($row){
			$grade=$row[0];$ifdefault=$row[1];$title=$row[2];$if2=$row[3];
			foreach ($sex_ARR as $v){@up_send_admindel('p/img/grade'.$v['i'].$grade.'.png');}
		}else{json_exit(array('flag'=>0,'msg'=>'forbidden'));}
		//删除用户组
		$db->query("DELETE FROM ".__TBL_ROLE__." WHERE id=".$id);
		//更新降级用户表
		$rolenum = $db->COUNT(__TBL_USER__,"grade=".$grade);
		if ($rolenum > 0){
			$row = $db->ROW(__TBL_ROLE__,"grade","kind=1 ORDER BY grade LIMIT 1","num");
			$newgrade  = $row[0];
			$db->query("UPDATE ".__TBL_USER__." SET grade=".$newgrade." WHERE grade=".$grade);
		}
		//如果当前删除的是默认组，则将最低权重设为默认组
		//获取最小权重roleid
		if ($ifdefault == 1){
			$row = $db->ROW(__TBL_ROLE__,"id","kind=1 ORDER BY grade LIMIT 1","num");
			$db->query("UPDATE ".__TBL_ROLE__." SET ifdefault=1 WHERE id=".$row[0]);
		}
		AddLog('删除用户组【'.$title.'，权重：'.$grade.'，时长：'.get_if2_title($if2).'】');
		json_exit(array('flag'=>1,'msg'=>'删除成功'));
	break;
	case "ajax_defaultupdate":
		if(!ifint($id))json_exit(array('flag'=>0,'msg'=>'forbidden'));
		$db->query("UPDATE ".__TBL_ROLE__." SET ifdefault=0 WHERE kind=1");
		$db->query("UPDATE ".__TBL_ROLE__." SET ifdefault=1 WHERE kind=1 AND id=".$id);
		json_exit(array('flag'=>1));
	break;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$urole  = json_decode($_ZEAI['urole'],true);
$sj_rmb1 = json_decode($_VIP['sj_rmb1'],true);
$sj_rmb2 = json_decode($_VIP['sj_rmb2'],true);
$contact_loveb = json_decode($_VIP['contact_loveb'],true);
$contact_daylooknum = json_decode($_VIP['contact_daylooknum'],true);
$chat_loveb = json_decode($_VIP['chat_loveb'],true);
$chat_daylooknum = json_decode($_VIP['chat_daylooknum'],true);
$photo_num = json_decode($_VIP['photo_num'],true);
$video_num = json_decode($_VIP['video_num'],true);
$loveb_buy = json_decode($_VIP['loveb_buy'],true);
$vipC      = json_decode($_VIP['vipC'],true);
$sj_loveb = json_decode($_VIP['sj_loveb'],true);
$trend_addflag = json_decode($_VIP['trend_addflag'],true);
$trend_bbsflag = json_decode($_VIP['trend_bbsflag'],true);
$viewlist = json_decode($_VIP['viewlist'],true);
$qianxian_num = json_decode($_VIP['qianxian_num'],true);
$meet_num = json_decode($_VIP['meet_num'],true);
$datingadd = json_decode($_VIP['datingadd'],true);
$chat_duifangfree = json_decode($_VIP['chat_duifangfree'],true);
$chat_send_iffree = json_decode($_VIP['chat_send_iffree'],true);
$chat_hf_iffree = json_decode($_VIP['chat_hf_iffree'],true);
$chat_duifangfree_send = json_decode($_VIP['chat_duifangfree_send'],true);

//$rziffree = json_decode($_VIP['rziffree'],true);
$hh_num   = json_decode($_VIP['hh_num'],true);
$rz_num   = json_decode($_VIP['rz_num'],true);
$vip_num  = json_decode($_VIP['vip_num'],true);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
<style>
#tmp input{margin-right:10px}
#tmp .tr{margin-bottom:10px}
.jsonlist{border-radius:2px;display:inline-block;background-color:#aaa;padding:2px 7px;margin:3px 10px 3px 0}
.jsonlistbox{width:500px;overflow:hidden;display:inline-block;float:left}
.tdL{background-color:#fafafa}
.box{min-width:1200px;padding:0}
.box .boxR{padding-bottom:66px}
</style>
</head>
<body>
<div class="box">
	<div class="boxL">
        <a href="urole.php" <?php echo (empty($submitok) || $submitok == 'add' || $submitok == 'mod')?' class="ed"':'';?>>VIP用户组套餐</a>
        <a href="urole.php?submitok=vipbanner" <?php echo ($submitok == 'vipbanner')?' class="ed"':'';?>>手机端VIP海报</a>
        <a href="urole.php?submitok=qx"<?php echo ($submitok == 'qx')?' class="ed"':'';?>>单次牵线收费</a>
	</div>
    <div class="boxR">
        <!--ADD-->
        <?php if ($submitok == "add" || $submitok == "mod") {
            if($submitok == "mod"){
                $row = $db->ROW(__TBL_ROLE__,"title,grade,if2","kind=1 AND id=".$id,"name");
                if ($row){
                    $title = dataIO($row['title'],'out');
                    $grade = $row['grade'];
                    $if2   = $row['if2'];
                }else{exit('forbidden');}
            }?>
            <style>
            .table.cols2 .tdL{width:180px}
            </style>
            <form id="ZEAIFORM" name="ZEAIFORM" method="post" enctype="multipart/form-data">
            <table class="table W95_ size2 cols2">
            <tr><td height="60" colspan="4" align="center" class="S18 B"><?php echo ($submitok == 'add')?'新增':'修改';?>用户组套餐</td></tr>
            <tr>
            <td class="tdL">用户组名称</td>
            <td align="left" class="tdR1"><input id="title" name="title" type="text" class="W300 size2" size="30" maxlength="20" placeholder="如：钻石会员，至尊会员，贵宾包月会员等" value="<?php echo $title;?>"></td>
            <td class="tdL"> 权重等级</td>
            <td align="left" class="tdR2"><input name="grade" type="text" class="W50 size2" id="grade" maxlength="2" value="<?php echo $grade;?>"> <span class="tips S12 C999">填1~10，数字越大级别越高，每个组权重不要相同</span></td>
            </tr>
        
            <?php
            $icopath1 = 'p/img/grade1'.$grade.'.png?'.ADDTIME;
            $pic_str1 = (up_check_file_exists($icopath1))?true:false;
            $pic_url1 = $_ZEAI['up2'].'/'.$icopath1;
            //
            $icopath2 = 'p/img/grade2'.$grade.'.png?'.ADDTIME;
            $pic_str2 = (up_check_file_exists($icopath2))?true:false;
            $pic_url2 = $_ZEAI['up2'].'/'.$icopath2;
            ?>
            <tr>
            <td class="tdL">尊享图标【男】</td>
            <td class="tdR">
                <?php if (up_check_file_exists('p/img/grade1'.$grade.'.png') && $submitok != "add" ){?>    
                    <a class="pic60" onClick="parent.piczoom('<?php echo $pic_url1; ?>')"><img src="<?php echo $pic_url1; ?>"></a>　
                    <a class="btn size1" onClick="parent.zeai.confirm('确定删除【男】图标重新上传么？',function(){zeai.openurl('urole'+zeai.ajxext+'submitok=delpicupdate&id=<?php echo $id; ?>&sg=1<?php echo $grade; ?>');})">删除</a>
                    <span class="tips S12">删除后可更换</span>　  
                <?php }else{echo "<input name='pic0' type='file' size='50' class='Caaa size2 W150' /><span class='tips S12'>必须为透明png格式，正方形，宽高60px</span>";}?>  
            </td>
            <td class="tdL">尊享图标【女】</td>
            <td class="tdR">
                <?php if (up_check_file_exists('p/img/grade2'.$grade.'.png')){?>    
                    <a class="pic60" onClick="parent.piczoom('<?php echo $pic_url2; ?>')"><img src="<?php echo $pic_url2; ?>"></a>　
                    <a class="btn size1" onClick="parent.zeai.confirm('确定删除【女】图标重新上传么？',function(){zeai.openurl('urole'+zeai.ajxext+'submitok=delpicupdate&id=<?php echo $id; ?>&sg=2<?php echo $grade; ?>');})">删除</a>
                    <span class="tips S12">删除后可更换</span
                ><?php }else{echo "<input name='pic1' type='file' size='50' class='Caaa size2 W150' /><span class='tips S12'>正方形透明png格式，60×60像素</span>";}?>  
            </td>
            </tr>
        
            <tr>
            <td class="tdL">服务价格【男】</td>
            <td class="tdR"><input name="sj_rmb1" id="sj_rmb1" type="text" class="W80 size2" maxlength="5" value="<?php echo $sj_rmb1[$grade.'_'.$if2];?>"> 元　　　　<span class="tips S12">普通会员可填0</span></td>
            <td class="tdL">服务价格【女】</td>
            <td class="tdR"><input name="sj_rmb2" id="sj_rmb2" type="text" class="W80 size2" maxlength="5" value="<?php echo $sj_rmb2[$grade.'_'.$if2];?>"> 元 <span class="tips S12">普通会员可填0</span></td>
            </tr>
            
            <tr>
            <td class="tdL">VIP有效期限</td>
            <td class="tdR"><input name="if2" type="text" class="W80 size2" maxlength="3" value="<?php echo $if2;?>"> 天　　　　<span class="tips S12">填1~999</span></td>
            <td class="tdL">限购次数</td>
            <td class="tdR"><input name="vip_num" type="text" class="W80 size2" maxlength="5" value="<?php echo $vip_num[$grade];?>"> 次
  <span class="tips">同一个用户最多在线升级当前等级次数，最少1次</span></td>
            </tr>
            
            <tr>
            <td class="tdL">在线充值<?php echo $_ZEAI['loveB'];?></td>
            <td class="tdR"><input name="loveb_buy" type="text" class="W80 size2" maxlength="4" value="<?php echo $loveb_buy[$grade];?>"> 折　　　　<span class="tips S12">1为原价，0.9对应9折</span></td>
            <td class="tdL">修改个人资料</td>
            <td class="tdR">
                <input type="radio" name="switch_sh_moddata" id="switch_sh_moddata1" class="radioskin" value="0"<?php echo ($switch['sh']['moddata_'.$grade] == 0)?' checked':'';?>>
                <label for="switch_sh_moddata1" class="radioskin-label"><i class="i1"></i><b class="W80">需要审核</b></label>
                
                <input type="radio" name="switch_sh_moddata" id="switch_sh_moddata2" class="radioskin" value="1"<?php echo ($switch['sh']['moddata_'.$grade] == 1)?' checked':'';?>>
                <label for="switch_sh_moddata2" class="radioskin-label"><i class="i1"></i><b class="W80">直接通过</b></label>
            </td>
            </tr>
            <tr>
              <td class="tdL">每天看联系方式总人数</td>
              <td class="tdR"><input name="contact_daylooknum" type="text" class="W80 size2" maxlength="5" value="<?php echo $contact_daylooknum[$grade];?>"> 人　　　　<span class="tips S12">填0为不能查看，填0下面按次将失效</span></td>
              <td class="tdL">上传头像照片</td>
              <td class="tdR">
        <input type="radio" name="switch_sh_photom" id="switch_photom1<?php echo $grade;?>" class="radioskin" value="0"<?php echo ($switch['sh']['photom_'.$grade] == 0)?' checked':'';?>>
        <label for="switch_photom1<?php echo $grade;?>" class="radioskin-label"><i class="i1"></i><b class="W80">需要审核</b></label>
        <input type="radio" name="switch_sh_photom" id="switch_photom2<?php echo $grade;?>" class="radioskin" value="1"<?php echo ($switch['sh']['photom_'.$grade] == 1)?' checked':'';?>>
        <label for="switch_photom2<?php echo $grade;?>" class="radioskin-label"><i class="i1"></i><b class="W80">直接通过</b></label>      
              
              </td>
              </tr>
            <tr>
              <td class="tdL">查看联系方式按次计费</td>
              <td class="tdR"><input name="contact_loveb" type="text" class="W80 size2" maxlength="5" value="<?php echo $contact_loveb[$grade];?>"> <?php echo $_ZEAI['loveB'];?>/人 　  <span class="tips S12">填0为免费查看，但不超过上面每天总人数</span></td>
              <td class="tdL">上传个人视频</td>
              <td class="tdR">
        <input type="radio" name="switch_sh_video" id="switch_video1<?php echo $grade;?>" class="radioskin" value="0"<?php echo ($switch['sh']['video_'.$grade] == 0)?' checked':'';?>>
        <label for="switch_video1<?php echo $grade;?>" class="radioskin-label"><i class="i1"></i><b class="W80">需要审核</b></label>
        <input type="radio" name="switch_sh_video" id="switch_video2<?php echo $grade;?>" class="radioskin" value="1"<?php echo ($switch['sh']['video_'.$grade] == 1)?' checked':'';?>>
        <label for="switch_video2<?php echo $grade;?>" class="radioskin-label"><i class="i1"></i><b class="W80">直接通过</b></label>      
              </td>
              </tr>
            <tr>
              <td class="tdL ">每天聊天解锁总人数</td>
              <td class="tdR"><input name="chat_daylooknum" type="text" class="W80 size2" maxlength="5" value="<?php echo $chat_daylooknum[$grade];?>"> 人　　　　<span class="tips S12">填0为不能解锁，填0下面按次将失效</span></td>
              <td class="tdL">上传个人相册</td>
              <td class="tdR">
        <input type="radio" name="switch_sh_photo" id="switch_photo1<?php echo $grade;?>" class="radioskin" value="0"<?php echo ($switch['sh']['photo_'.$grade] == 0)?' checked':'';?>>
        <label for="switch_photo1<?php echo $grade;?>" class="radioskin-label"><i class="i1"></i><b class="W80">需要审核</b></label>
        <input type="radio" name="switch_sh_photo" id="switch_photo2<?php echo $grade;?>" class="radioskin" value="1"<?php echo ($switch['sh']['photo_'.$grade] == 1)?' checked':'';?>>
        <label for="switch_photo2<?php echo $grade;?>" class="radioskin-label"><i class="i1"></i><b class="W80">直接通过</b></label>      
              </td>
              </tr>
            <tr>
              <td class="tdL ">聊天解锁按次计费</td>
              <td class="tdR"><input name="chat_loveb" type="text" class="W80 size2" maxlength="5" value="<?php echo $chat_loveb[$grade];?>"> <?php echo $_ZEAI['loveB'];?>/人 　 <span class="tips S12">填0为免费解锁，但不超过上面每天总人数</span></td>
              <td class="tdL">相册容量</td>
              <td class="tdR"><input name="photo_num" type="text" class="W80 size2" maxlength="5" value="<?php echo $photo_num[$grade];?>"> 张</td>
              </tr>
                
                <tr>
                <td rowspan="5" class="tdL">聊天特权</td>
                <td rowspan="5" class="tdR lineH150">
                
                聊天总开关 <input type="checkbox" class="switch" name="chat_send_iffree" id="chat_send_iffree" value="1"<?php echo ($chat_send_iffree[$grade]==1)?' checked':'';?>><label for="chat_send_iffree" class="switch-label"><i></i><b>开启</b><b>关闭</b></label><br><span class="tips2 S12" style="display:inline-block">
                开启后此用户组可以聊天，关闭后不能聊天（花钱也没用），触发解锁机制<br>推荐VIP开启</span>
                <div style="border-top:#eee 1px solid;padding:10px 0">
                    对方免费主动发起聊天 <input type="checkbox" class="switch" name="chat_duifangfree_send" id="chat_duifangfree_send" value="1"<?php echo ($chat_duifangfree_send[$grade]==1)?' checked':'';?>><label for="chat_duifangfree_send" class="switch-label"><i></i><b>开启</b><b>关闭</b></label><br><span class="tips2 S12" style="display:inline-block">
                    【聊天总开关】必须开启才会生效，不计入每天总人数<br>开启后对方给此用户组可以免费主动发起聊天；关闭后触发解锁机制；推荐最顶级VIP开启</span>
                </div>
        
                <div style="border-top:#eee 1px solid;padding:10px 0">
                    免费回复聊天 <input type="checkbox" class="switch" name="chat_hf_iffree" id="chat_hf_iffree" value="1"<?php echo ($chat_hf_iffree[$grade]==1)?' checked':'';?>><label for="chat_hf_iffree" class="switch-label"><i></i><b>开启</b><b>关闭</b></label><br><span class="tips2 S12" style="display:inline-block">
                    【聊天总开关】必须开启才会生效，不计入每天总人数<br>开启后此用户组可以免费回复聊天；关闭后触发解锁机制；推荐最顶级VIP开启</span>
                </div>
                  </td>
                <td class="tdL">视频容量</td>
                <td class="tdR"><input name="video_num" type="text" class="W80 size2" maxlength="5" value="<?php echo $video_num[$grade];?>">
        个</td>
                </tr>
                <tr>
                  <td class="tdL">发布约会</td>
                  <td class="tdR"><input type="checkbox" class="switch" name="datingadd" id="datingadd" value="1"<?php echo ($datingadd[$grade]==1)?' checked':'';?>><label for="datingadd" class="switch-label"><i></i><b>开启</b><b>关闭</b></label><br><span class="tips2 S12">开启后，此用户组可以发布约会，关闭提示升级</span> </td>
                </tr>
                <tr>
                  <td class="tdL">浏览谁看过我列表</td>
                  <td class="tdR"><input type="checkbox" class="switch" name="viewlist" id="viewlist" value="1"<?php echo ($viewlist[$grade]==1)?' checked':'';?>>
                    <label for="viewlist" class="switch-label"><i></i><b>开启</b><b>关闭</b></label>
                    <br>
                    <span class="tips2 S12">开启后，此用户组可以查看访客列表，关闭提示升级</span>          
                  </td>
                </tr>
                <tr>
                  <td class="tdL">动态/单身群话题</td>
                  <td class="tdR"><input type="radio" name="trend_addflag" id="trend_addflag0" class="radioskin" value="0"<?php echo ($trend_addflag[$grade] == 0)?' checked':'';?>>
                    <label for="trend_addflag0" class="radioskin-label"><i class="i1"></i><b class="W80 S14">需要审核</b></label>
                    <input type="radio" name="trend_addflag" id="trend_addflag1" class="radioskin" value="1"<?php echo ($trend_addflag[$grade] == 1)?' checked':'';?>>
                  <label for="trend_addflag1" class="radioskin-label"><i class="i1"></i><b class="W80 S14">直接通过</b></label></td>
                </tr>
                <tr>
                  <td class="tdL">动态/单身群评论</td>
                  <td class="tdR"><input type="radio" name="trend_bbsflag" id="trend_bbsflag0" class="radioskin" value="0"<?php echo ($trend_bbsflag[$grade] == 0)?' checked':'';?>>
                    <label for="trend_bbsflag0" class="radioskin-label"><i class="i1"></i><b class="W80 S14">需要审核</b></label>
                    <input type="radio" name="trend_bbsflag" id="trend_bbsflag1" class="radioskin" value="1"<?php echo ($trend_bbsflag[$grade] == 1)?' checked':'';?>>
                  <label for="trend_bbsflag1" class="radioskin-label"><i class="i1"></i><b class="W80 S14">直接通过</b></label></td>
                </tr>
                <tr>
                  <td class="tdL ">查看聊天免费绿色通道</td>
                  <td class="tdR lineH150"><input type="checkbox" class="switch" name="chat_duifangfree" id="chat_duifangfree" value="1"<?php echo ($chat_duifangfree[$grade]==1)?' checked':'';?>><label for="chat_duifangfree" class="switch-label"><i></i><b>开启</b><b>关闭</b></label><br><span class="tips2 S12" style="display:inline-block">
                开启后，此用户组可以查看对方发过来的聊天信息，免费解锁，直接查看聊天内容<br>
                关闭后，触发解锁机制；推荐最顶级VIP会员开启
                </span></td>
                  <td class="tdL">赠送<?php echo $_ZEAI['loveB'];?></td>
                  <td class="tdR"><input name="sj_loveb" type="text" class="W80 size2" maxlength="7" value="<?php echo $sj_loveb[$grade];?>"> <?php echo $_ZEAI['loveB'];?><br><span class="tips2">在线升级此等级后，赠送<?php echo $_ZEAI['loveB'];?>，填0为不送</span></td>
                </tr>     
              
              <tr>
              <td valign="top" class="tdL">用户服务模式</td>
              <td valign="top" class="tdR lineH150" style="padding-top:12px;">
              
                <input type="radio" name="switch_Smode" id="switch_Smode1" class="radioskin" value="1"<?php echo ($switch['Smode']['g_'.$grade] == 1)?' checked':'';?>>
                <label for="switch_Smode1" class="radioskin-label"><i class="i1"></i><b class="W100">线上自助服务</b></label>
                
                <input type="radio" name="switch_Smode" id="switch_Smode2" class="radioskin" value="2"<?php echo ($switch['Smode']['g_'.$grade] == 2)?' checked':'';?>>
                <label for="switch_Smode2" class="radioskin-label"><i class="i1"></i><b class="W100">线下人工服务</b></label>
                <br>
              <span class="tips2 S12" style="margin-top:5px;display:inline-block">
                　1．选择【线上自助服务】，此用户组主页将显示联系方式和私信聊天入口<br>
                　2．选择【线下人工服务】，此用户组主页将隐藏联系方式和私信聊天入口<br>　　　联系唯一途径就是寻求官方红娘来牵线<br>
              </span>
              </td>
              <td valign="top" class="tdL">赠送互换</td>
              <td valign="top" class="tdR"><input name="hh_num" type="text" class="W80 size2" maxlength="5" value="<?php echo $hh_num[$grade];?>"> 次
  <div class="tips2">在线升级此等级后，赠送用户发起和对方互换联系方式(微信或手机)次数，如果不足提示升级VIP获得更多次数，也可以给某一个用户在【用户管理>修改>基本信息】单独修改次数<br>
    推荐最顶级VIP设99次</div></td>
              </tr>
              <tr>
              <td rowspan="2" valign="top" class="tdL"><br>
                VIP套餐详情</td>
              <td rowspan="2" valign="top" class="tdR lineH150"><textarea name="vipC" id="vipC" placeholder="如：&#13;&#10;&#13;&#10;可以享受专属红娘1对1牵线服务10次&#13;&#10;可以享受2次线下单身交友派对" rows="6" class="W100_ S14"><?php echo dataIO($vipC[$grade],'wx');?></textarea><span class="tips2 S12">如果要加红特出显示，可以用b标签来特出，如&lt;b&gt;我是红色&lt;/b&gt; <font style="color:#FD66B5">我是红色</font><br>
        支持简单的标准HTML代码，请在官方指导下进行修改</span>
        </td>
              <td height="10" valign="top" class="tdL">赠送红娘牵线</td>
              <td valign="top" class="tdR"><input name="qianxian_num" type="text" class="W80 size2" maxlength="5" value="<?php echo $qianxian_num[$grade];?>"> 次
              <div class="tips2">在线升级此等级后，赠送用户在前台主动发起红娘牵线次数，填0不能主动发起申请（将引导加红娘微信）<br>大于0用完后会引导升级VIP享受更多自助牵线次数<br>发起委托申请后对应红娘将收到微信通知（需绑定）</div>
              </td>
              </tr>
              <tr>
                <td valign="top" class="tdL">赠送免费认证</td>
                <td valign="top" class="tdR"><!--<input type="checkbox" class="switch" name="rziffree" id="rziffree" value="1"<?php echo ($rziffree[$grade]==1)?' checked':'';?>><label for="rziffree" class="switch-label"><i></i><b>开启</b><b>关闭</b></label><br><span class="tips2 S12">开启后，此用户组诚信认证将免费，关闭后根据总认证设置</span>-->
        <input name="rz_num" type="text" class="W80 size2" maxlength="5" value="<?php echo $rz_num[$grade];?>"> 次
        <div class="tips2">在线升级此等级后，赠送用户在前台主动实名和真人认证免费次数，也可以给某一个用户在【用户管理】单独修改次数，推荐普通会员2次，VIP会员4次</div>          
                </td>
              </tr>
              </table>
            
                <?php if ($submitok == "add") {?>
                    <input name="submitok" id="submitok" type="hidden" value="ajax_addupdate">
                <?php }elseif($submitok == "mod"){ ?>
                    <input name="submitok" id="submitok" type="hidden" value="ajax_modupdate">
                    <input name="oldgrade" type="hidden" value="<?php echo $grade;?>">
                    <input name="id" type="hidden" value="<?php echo $id;?>">
                <?php }?>
                <input name="uu" id="uu" type="hidden" value="<?php echo $session_uid;?>">
                <input name="pp" id="pp" type="hidden" value="<?php echo $session_pwd;?>">
                <input name="roleid" id="roleid" type="hidden" value="<?php echo $id;?>">
            </form>
            <!--ADD END-->
        <?php }elseif($submitok=='qx'){?>
            <form id="ZEAI_CN___FORM">
            <table class="table size2 W700" style="margin:20px 0 0 20px">
            <tr>
                <td class="tdL">单次牵线价格</td>
                <td class="tdR">
                <input name="qx_1price" type="text" class="input size2 W50" id="qx_1price" value="<?php echo $_VIP['qx_1price'];?>"size="50" maxlength="5"> 元
                <div class="tips2">用户购买后，将获得一次红娘人工牵线机会，VIP组里面赠送次数为0或用完了，就自动打开单次购买；填0后关闭，只能加红娘微信二维码</div>
                </td>
            </tr> 
            <tr>
                <td class="tdL">简短说明</td>
                <td class="tdR">
                <textarea name="qx_1price_C" id="qx_1price_C" placeholder="100字以内说明" rows="6" class="W100_ S14"><?php echo dataIO($_VIP['qx_1price_C'],'wx');?></textarea>
            	</td>
            </tr>    
            <tr>    
                <td colspan="2" align="center">
                <input name="submitok" type="hidden" value="cache_qx_1price">
                <input name="uu" id="uu" type="hidden" value="<?php echo $session_uid;?>">
                <input name="pp" id="pp" type="hidden" value="<?php echo $session_pwd;?>">
                <button type="button" id="save" class="btn size3">确定并保存</button>
                </td>
            </tr>
            </table>
            </form>
			<script>
            save.onclick = function(){
				zeai.ajax({url:'<?php echo HOST;?>/sub/cache'+zeai.extname,form:ZEAI_CN___FORM},function(e){var rs=zeai.jsoneval(e);
					zeai.msg(rs.msg);
					setTimeout(function(){location.reload(true);},1000);
				});
            }
            </script>
        <?php }elseif($submitok=='vipbanner'){?> 
            <form id="ZEAI_CN___FORM">
            <table class="table size2" style="margin:20px 0 0 20px">
            <tr><th colspan="2" align="left">尺寸：<font class="Cf00">750*350</font>像素，类型:.jpg，图片大小在200K以内，将显示在经典风格手机端VIP升级页面</th></tr> 
            <tr>
                <td class="tdL">VIP海报</td>
                <td class="tdR">
                
                <?php if (!empty($_VIP['vipbanner'])) {?>
                    <img width="300" height="140" src="<?php echo $_ZEAI['up2']."/".$_VIP['vipbanner']; ?>" class="zoom" align="absmiddle" onClick="parent.piczoom('<?php echo $_ZEAI['up2']."/".$_VIP['vipbanner']; ?>')">　
                    <a href="#" onClick="vipbannerDel()" class="btn size1" >删除</a>　<span class="tips">先删除后更换</span>
                <?php }else{ 
                    echo "<input name=pic type=file size=30 class='input size2' />";
                }?>
                
            </td>
            </tr>    
            <tr>
                <td class="tdL">url链接</td>
                <td class="tdR"><input name="vipbanner_url" type="text" class="input size2 W500" id="vipbanner_url" value="<?php echo $_VIP['vipbanner_url'];?>"size="50" maxlength="100"><span class="tips">没有请留空</span></td>
            </tr> 
            <tr>    
                <td colspan="2" align="center">
                <input name="submitok" type="hidden" value="cache_vipbanner">
                <input name="uu" id="uu" type="hidden" value="<?php echo $session_uid;?>">
                <input name="pp" id="pp" type="hidden" value="<?php echo $session_pwd;?>">
                <button type="button" id="save" class="btn size3">确定并保存</button>
                </td>
            </tr>
            </table>
            </form>
			<script>
            function vipbannerDel(){
                zeai.confirm('确定要删除么？',function(){
                    zeai.ajax({url:'<?php echo HOST;?>/sub/cache'+zeai.extname,data:{submitok:'cache_vipbannerDel',uu:uu.value,pp:pp.value}},function(e){var rs=zeai.jsoneval(e);
                        zeai.msg(rs.msg);
                        if (rs.flag == 1){setTimeout(function(){location.reload(true);},1000);}else{zeai.alert(rs.msg);}
                    });
                });
            }
            save.onclick = function(){
                zeai.confirm('确定要保存么？此修改将触发缓存机制同步更新，立即生效！',function(){
                    zeai.ajax({url:'<?php echo HOST;?>/sub/cache'+zeai.extname,form:ZEAI_CN___FORM},function(e){var rs=zeai.jsoneval(e);
                        zeai.msg(rs.msg);
                        setTimeout(function(){location.reload(true);},1000);
                    });
                });
            }
            </script>
    		<!--vipbanner END-->
        <?php }else{?>
        <!--LIST-->
            <?php
            $rt = $db->query("SELECT id,title,authoritylist,grade,if2,ifdefault,flag FROM ".__TBL_ROLE__." WHERE kind=1 ORDER BY grade");
            $total = $db->num_rows($rt);
            if ($total <= 0 ) {
				if ($submitok !== "add"){
					echo "<div class='nodataico'><i></i>暂无信息";
					echo"<br><a class='aQINGed' href='".SELF."?submitok=add'>新增用户组</a>";
					echo "</div>";
				}	
            } else {?>
                <div class="topsearch">
                	<button type="button" class="btn " onClick="zeai.openurl('<?php echo SELF;?>?submitok=add')"><i class="ico add">&#xe622;</i> 新增用户组</button>
                    <div class="rbox">
            			<span class="tips2 S12 C999"><i class="ico Cf60">&#xe65c;</i>系统默认权重1为普通会员，大于1为VIP会员，无特殊情况请按默认4个组</span>
                    </div>
                </div>            

            <table class="tablelist">
            <tr>
                <th width="60" align="center">权重</th>
                <th width="70" align="center">尊享图标</th>
                <th width="20" align="center">&nbsp;</th>
                <th width="150">用户组名称</th>
                <th width="60">服务类型</th>
                <th width="80">时长</th>
                <th width="100">服务价格（元）</th>
                <th width="59">用户数量</th>
                <th width="100">默认用户组</th>
                <th>&nbsp;</th>
                <th width="100" align="center">VIP升级列表显示</th>
                <th width="60" class="center">用户组权限</th>
                <th width="60" class="center">删除</th>
                <th width="20" class="center">&nbsp;</th>
            </tr>
            <?php
            for($i=1;$i<=$total;$i++) {
                $rows = $db->fetch_array($rt,"name");
                if(!$rows) break;
                $id = $rows['id'];
                $title = dataIO($rows['title'],'out');
                $grade = intval($rows['grade']);
                $if2   = intval($rows['if2']);
                $ifdefault = $rows['ifdefault'];
                $flag = $rows['flag'];
                $unum = $db->COUNT(__TBL_USER__,"kind<>4 AND grade=".$grade);
				?>
				<tr>
				<td width="60" height="60" align="center" class="S14"><?php echo $grade;?></td>
				<td width="70" height="60" align="center">
					<?php
					foreach ($sex_ARR as $v) {
						$icopath = 'p/img/grade'.$v['i'].$grade.'.png';
						$pic_url = $_ZEAI['up2'].'/'.$icopath;
						//$pic_str = (up_check_file_exists($icopath))?'<img width="30" height="30" src="'.$pic_url.'?'.ADDTIME.'">':'';
						$pic_str = '<img width="30" height="30" src="'.$pic_url.'?'.ADDTIME.'">';
					?><a onClick="piczoom('<?php echo $pic_url; ?>')"><?php echo $pic_str; ?></a><?php }?>
				</td>
				<td width="20" align="center">&nbsp;</td>
				<td width="150" class="S14"><?php echo $title;?></td>
				<td width="60" class="S14"><?php echo ($switch['Smode']['g_'.$grade] == 1)?'线上':'线下';?></td>
				<td width="80" class="S14"><?php if($grade>1)echo get_if2_title($if2);?></td>
				<td width="100" class="S14 C666">
				<?php if ($grade>1){
				$rmb1 = abs(floatval($sj_rmb1[$grade.'_'.$if2]));
				$rmb2 = abs(floatval($sj_rmb2[$grade.'_'.$if2]));
				?>
				男：<?php echo ($rmb1>0)?'<font class="S12 Cf00">￥</font><font class="Cf00">'.$rmb1.'</font>':'免费';?><br>
				女：<?php echo ($rmb2>0)?'<font class="S12 Cf00">￥</font><font class="Cf00">'.$rmb2.'</font>':'免费';?>
				<?php }else{ ?>
				免费
				<?php }?>
				</td>
				<td width="59" class="S14">
                <?php if ($grade>1){?>
                <a href="u.php?g=2&ugrade=<?php echo $grade;?>" class="aBAI"><?php echo $unum;?></a>
                <?php }else{echo $unum;}?>
                </td>
				<td width="100">
			  <?php if ($ifdefault == 1){?>
			  <a class="aQINGed not-allowed tips" title="<?php echo $title;?>" tips-title="默认第一次注册用户组<br>更改请到【系统配置】->【注册设置】修改">默认组</a>
			  <?php }else{ ?>
			  <a tips-title="默认第一次注册的用户组" title="<?php echo $title;?>" value="<?php echo $id; ?>" class="aQING tips" style="display:none">设为默认组</a>
			  <?php }?>
			</td>
				<td>&nbsp;</td>
			<td width="100" align="center">
			<?php if ($grade>1){?>
			<input type="checkbox" id="flag<?php echo $id;?>" class="switch" value="<?php echo $flag;?>"<?php echo ($flag == 1)?' checked':'';?>><label value="<?php echo $id;?>" for="flag<?php echo $id;?>" class="switch-label"><i></i><b>显示</b><b>隐藏</b></label>
			<?php }?>
			</td>
				<td width="60" class="center"><a value="<?php echo $id;?>" class="editbtn" title="修改<?php echo $title;?>" onClick="zeai.openurl('<?php echo SELF;?>?submitok=mod&id=<?php echo $id;?>')"></a></td>
				<td width="60" class="center"><?php if ($grade>1){?><a value="<?php echo $id; ?>" unum="<?php echo $unum;?>" class="delbtn" title="<?php echo $title;?>"></a><?php }?></td>
				<td width="20" class="center">&nbsp;</td>
				</tr>
            <?php } ?>

            </table>
            <?php } ?>
        <?php } ?>
        
        
	</div>
    <div class="clear"></div>
</div>
<?php if ($submitok == "add" || $submitok == "mod") {?>
<div class="savebtnbox"><button type="button" class="btn size3" id="save">确定并保存</button></div>
<?php }?>
<script>
<?php if ($submitok == "add" || $submitok == "mod") {?>
	save.onclick = function(){
		zeai.ajax({url:'urole'+zeai.extname,form:ZEAIFORM},function(e){var rs=zeai.jsoneval(e);
			zeai.msg(0);
			if (rs.flag == 1){
				zeai.msg(0);zeai.msg('正在生成高速缓存',{time:30});
				o('submitok').value='cache_config_vip';
				zeai.ajax({url:'<?php echo HOST;?>/sub/cache'+zeai.extname,form:ZEAIFORM},function(e){var rs=zeai.jsoneval(e);
					zeai.msg(0);zeai.msg(rs.msg);
					if (rs.flag == 1){
						setTimeout(function(){zeai.openurl('urole'+zeai.extname)},1000);
					}
				});
			}else if(rs.flag == 0){
				zeai.msg(rs.msg,o(rs.focus));
			}else{
				zeai.msg(rs.msg);
			}
		});
	}
<?php }else{ ?>
	zeai.listEach('.switch-label',function(obj){
		obj.onclick = function(){
			var id = parseInt(obj.getAttribute("value"));
			var chkobj  = o('flag'+id);
			setTimeout(function(){
				var chkV = chkobj.checked;
				var flag = (chkobj.checked)?1:0;
				var postjson = {submitok:'cache_config_urole_flag',id:id,flag:flag,uu:'<?php echo $session_uid;?>',pp:'<?php echo $session_pwd;?>'};
				zeai.ajax({url:'<?php echo HOST;?>/sub/cache'+zeai.extname,data:postjson},function(e){var rs=zeai.jsoneval(e);
					zeai.msg(rs.msg);
					if (rs.flag == 1){setTimeout(function(){location.reload(true);},1000);}
				});
			},300);
		}
	});

	zeai.listEach('.delbtn',function(obj){
		obj.onclick = function(){
			var id = parseInt(obj.getAttribute("value"));
			var unum = parseInt(obj.getAttribute("unum"));
			var title = obj.getAttribute("title");
			var tips = (unum>0)?'当前组包含 <font class="Cf00">'+unum+'</font> 个用户，删除后这些用户将被降级为普通会员':'';
			zeai.confirm('<i class="S18 ico">&#xe604;</i> <b class="S18">请慎重</b><br>'+tips+'真的要删除【'+title+'】么？',function(){
				zeai.ajax('urole'+zeai.ajxext+'submitok=ajax_delupdate&id='+id,function(e){var rs=zeai.jsoneval(e);
					if (rs.flag == 1){urolecache();location.reload(true);}else{zeai.msg(rs.msg);}
				});
			});
		}
	});
	
	zeai.listEach('.aQING',function(obj){
		obj.onclick = function(){
			var id = parseInt(obj.getAttribute("value"));
			var title = obj.getAttribute("title");
			zeai.confirm('<font color="red">请慎重！</font><br>'+'真的要将【'+title+'】设为默认用户组么？',function(){
				zeai.ajax('urole'+zeai.ajxext+'submitok=ajax_defaultupdate&id='+id,function(e){var rs=zeai.jsoneval(e);
					if (rs.flag == 1){urolecache();location.reload(true);}else{zeai.msg(rs.msg);}
				});
			});
		}
	});
<?php } ?>
	function urolecache(){
		var postjson = {submitok:'cache_config_roleinfo',uu:'<?php echo $session_uid;?>',pp:'<?php echo $session_pwd;?>'};
		zeai.ajax({url:'<?php echo HOST;?>/sub/cache'+zeai.extname,data:postjson});
	}
</script>
<?php require_once 'bottomadm.php';?>